import { createApp } from 'vue'
import './style.css';
import App from './App.vue'
import router from './router/router'
import { ESObjectsManager, ES3DTileset, ESTerrainLayer } from 'earthsdk3';
import { ESCesiumViewer } from 'earthsdk3-cesium';
import { ESUeViewer } from 'earthsdk3-ue';

const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
//const objm = new ESObjectsManager(ESCesiumViewer);
//const objm = new ESObjectsManager(ESUeViewer);

//@ts-ignore
window.g_objm = objm;

createApp(App, { objm }).use(router).mount('#app')

// 监听视口创建完成事件
objm.viewerCreatedEvent.don((viewer) => {
    initScene(objm)
    viewer.clickEvent.don((e) => {
        //此处增加构建交互逻辑
        //       console.log("点击屏幕", e.screenPosition);
    });
});


function initScene(objm: ESObjectsManager) {
    //影像图层
    objm.sceneTree.createSceneObjectTreeItemFromJson({
        "id": "ae103185-08c7-4ed0-b6d4-15ad77bbbf66",
        "type": "ESImageryLayer",
        //        "url": "https://t3.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=01045099f27b57f849495a8ea7c3a71d",
        "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
        "maximumLevel": 18,
        "name": "全球影像",
        "allowPicking": true
    })

    // const sceneObject = objm.createSceneObject(ES3DTileset, "bim-model1")
    // if (!sceneObject) return
    // sceneObject.url = '/data/储能电站/dc/tileset.json'

    // const terrainLayer = objm.createSceneObject(ESTerrainLayer)
    // if (!terrainLayer) return
    // terrainLayer.url = "/data/储能电站/cesium/layer.json"

    // sceneObject.offset = [475268.33, -852566.69, 0]
    // 加载完成事件
    // sceneObject.tilesetReady.don(() => {
    //     sceneObject.flyTo()
    // })
}
